package me.hys.service.doctor.impl;

import java.util.List;
import java.util.Map;

import me.hys.base.PageQuery;
import me.hys.dao.doctor.IAnswerMapper;
import me.hys.entity.doctor.AnswerEntity;
import me.hys.service.doctor.IAnswerManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Author: @author HYS . <br>
 * Date: 2015-10-7 下午7:47:32 . <br>
 * Function:
 */
@Service
@Transactional
class AnswerManagerImpl implements IAnswerManager {
	@Autowired
	private IAnswerMapper answerMapper;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * me.hys.service.doctor.IAnswerManager#findMsgPage(me.hys.base.PageQuery)
	 */
	@Override
	public PageQuery<AnswerEntity> findPage(PageQuery<AnswerEntity> page) {
		Map<String, Object> condition = page.getCondition();
		List<AnswerEntity> list = answerMapper.findPage(condition);
		page.setList(list);
		page.setTotal(answerMapper.findPageCount(condition));
		// 总页数
		int size = (int) Math.ceil(page.getTotal() * 1.0f / page.getLimit());
		page.setSize(size);
		return page;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * me.hys.service.doctor.IAnswerManager#insert(me.hys.entity.doctor.AnswerEntity
	 * )
	 */
	@Override
	public int save(AnswerEntity entity) {
		answerMapper.save(entity);
		return entity.getId();
	}
}
